package data;

/**
 * ...
 * @author Axel Huizinga axel@cunity.me
 */

class Group implements Dynamic
{
	public var description(default, null):String;
	public var name(default, null):String;
	public var items(default, null):List<Item>;
	
	var dataMap:Hash<Xml>;
	
	public function new(xData:Xml) 
	{
		for (a in xData.attributes())		
			Reflect.setField(this, a, xData.get(a));		
			
		dataMap = new Hash();		
		for (map in xData.elementsNamed('DataMap'))
			for(d in map.elements())
				dataMap.set(d.nodeName, d);				

		var descNode:Xml = null;
		if (xData.elementsNamed('Description').hasNext())
			descNode = xData.elementsNamed('Description').next();
		//trace(descNode.nodeName + ':' + descNode.nodeType + ':' + descNode.firstChild().nodeValue);
		description = descNode.firstChild().nodeValue;
		//trace('description:' +description);
		items = new List();
		for (i in xData.elementsNamed('Item'))
		{
			var item:Item = new Item(i);
			item.dataMap = dataMap;
			items.add(item);
		}
		trace(items.length);
	}
	
}